#查找并整合（如果原来没有）所有lib/cpp/*/include的头文件
#目录下必须有src或Src文件夹，否则跳过

import os
exists=os.path.exists
isdir=os.path.isdir
listdir=os.listdir
chdir=os.chdir
mkdir=os.mkdir
chdir("lib/cpp")

#递归获取并写入
def _getheaderlist(path:str,cur:list[str])->None:
    for s in cur:
        file=f"{path}/{s}"
        if isdir(file):
            dst=f"../include/{file}"
            mkdir(dst)
            _getheaderlist(file,listdir(file))
            continue
        if s.endswith(".h") or s.endswith(".hpp"):
            with open(f"../include/{file}","w") as f:
                with open(file,"r") as g:
                    f.write(g.read())

def getheaderlist():
    _getheaderlist(".",listdir("."))

for lib_dir in listdir("."):
    chdir(lib_dir)
    if exists("include"):
        print(f"skip {lib_dir}")
        chdir("..")
        continue
    mkdir("include")
    if exists("src") or exists("Src"):
        chdir("src")
        getheaderlist()
        chdir("..")
    chdir("..")